/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VelocityRendererPanel.java
 *
 * Created on Nov 22, 2011, 5:58:25 PM
 */
package gui;

import flowvis.VelocityRenderer;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 *
 * @author waldo
 */
public class VelocityRendererPanel extends javax.swing.JPanel {

    /**
     * Renderer object
     */
    VelocityRenderer velocityRenderer;

    /**
     * Constructor.<br>
     * @TODO Document
     * @param velocityRenderer 
     */
    public VelocityRendererPanel( VelocityRenderer velocityRenderer ) {
        initComponents();
        this.velocityRenderer = velocityRenderer;
        vColoringCombobox.setSelectedIndex( velocityRenderer.getColoring() );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        vColoringCombobox = new javax.swing.JComboBox();

        vColoringCombobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Gray scale", "Rainbow", "Rainbow (banded)", "Black body", "Black body (banded)" }));
        vColoringCombobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vColoringComboboxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(216, Short.MAX_VALUE)
                .addComponent(vColoringCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(vColoringCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(488, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void vColoringComboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vColoringComboboxActionPerformed
        velocityRenderer.setColoring( vColoringCombobox.getSelectedIndex() );
        this.updateUI();
    }//GEN-LAST:event_vColoringComboboxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    /**
    * Painting of color legend.
    * First implementation: only for black body
    * @autor waldo
    */
    @Override public void paintComponent( Graphics g ){
        super.paintComponent(g);
        // Starting point, as well as width and height for the color legend.
        final int xi = 20, yi=60, w = 30, h=240;
        Graphics2D g2d = (Graphics2D)g;
        switch( velocityRenderer.getColoring() ){
            case VelocityRenderer.COLOR_BLACKWHITE:
            Color bw0 = new Color(0,0,0);
            Color bw1 = new Color(255,255,255);
            GradientPaint gp1 = new GradientPaint(
                xi, yi, bw1,
                xi, yi+h, bw0
            );
            g2d.setPaint(gp1);
            g2d.fillRect(xi, yi, w, h);
            break;
            case VelocityRenderer.COLOR_BLACKBODY:
            // Black body colors
            Color bb0 = new Color(0, 0, 0);
            Color bb1 = new Color(255, 0, 0);
            Color bb2 = new Color(255, 255, 0);
            Color bb3 = new Color(255, 255, 255);
            /*to be used with color banding:
            g2d.setPaint( bg );
            g2d.fillRect(xi, y1, 10, 40);*/
            gp1 = new GradientPaint(
                xi, yi, bb3,
                xi, yi+h/3, bb2//, true // <-- 'true' is just to check the correct position of the gradient
            );
            g2d.setPaint(gp1);
            g2d.fillRect(xi, yi, w, h/3);
            gp1 = new GradientPaint(
                xi, yi-1+h/3, bb2,
                xi, yi+2*h/3, bb1//, true
            );
            g2d.setPaint(gp1);
            g2d.fillRect(xi, yi-1+h/3, w, h/3);
            gp1 = new GradientPaint(
                xi, yi-1+2*h/3, bb1,
                xi, yi+h, bb0//, true
            );
            g2d.setPaint(gp1);
            g2d.fillRect(xi, yi-1+2*h/3, w, h/3);
            break;
            case VelocityRenderer.COLOR_BLACKBODY_BANDS:
            int l = velocityRenderer.getNLevels();
            Color[] cs = new Color[l+1];

            break;
        }

    }

    private javax.swing.JComboBox vColoringCombobox;
    // End of variables declaration//GEN-END:variables
}
